﻿using KnifeZ.PersonalNotePad.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using KnifeZ.XamarinDomain.Extensions;

namespace KnifeZ.PersonalNotePad.Views
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MenuPage : ContentPage
    {
        MainPage RootPage { get => Application.Current.MainPage as MainPage; }
        List<HomeMenuItem> menuItems;
        public MenuPage()
        {
            InitializeComponent();
            menuItems = new List<HomeMenuItem>();
            foreach (var menuType in ExtensionsEnum.EnumToDictionary(typeof(MenuItemType)))
            {
                menuItems.Add(new HomeMenuItem()
                {
                    Id = (MenuItemType)menuType.Key,
                    Title = menuType.Value
                });
            }
            //menuItems = new List<HomeMenuItem>
            //{
            //    new HomeMenuItem {Id = MenuItemType.Browse, Title= MenuItemType.Browse.GetDescription() },
            //    new HomeMenuItem {Id = MenuItemType.About, Title=MenuItemType.About.GetDescription() }
            //};

            ListViewMenu.ItemsSource = menuItems;

            ListViewMenu.SelectedItem = menuItems[0];
            ListViewMenu.ItemSelected += async (sender, e) =>
            {
                if (e.SelectedItem == null)
                    return;

                var id = (int)((HomeMenuItem)e.SelectedItem).Id;
                await RootPage.NavigateFromMenu(id);
            };
        }
    }
}